<?php
/**
 * Created by PhpStorm.
 * UsersF: Mloong
 * Date: 2018/12/3
 * Time: 10:09
 */

namespace app\api\service;


use think\cache\driver\Redis;

class RedisService
{
    private $redis;
    public function __construct()
    {
        $this->redis = new \Driver\Cache\Redis();
    }

    # 验证码写入redis-hash  有效期为5分钟
    public function setMessage($phone,$code)
    {
        $result = $this->redis->set("PhoneNum_".$phone,$code,300);
        return $result;
    }
    # 判断验证码是否失效 不失效则返回
    public function checkMessage($phone)
    {
        $redis_code = $this->redis->get("PhoneNum_".$phone);
        return $redis_code;
    }
    # 删除redis缓存
    public function delMessage($phone)
    {
        return $this->redis->DelKey("PhoneNum_".$phone);
    }
    public function testCheckMessage($phone)
    {
        $redis_key = config('redis.test_message').$phone;
        $redis_code = $this->redis->get($redis_key);
        return $redis_code;
    }
    public function testDelMessage($phone)
    {
        $redis_key = config('redis.test_message').$phone;
        return $this->redis->DelKey($redis_key);
    }
}